package com.wealth.lottery.repository;

import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.wealth.lottery.entity.LotteryRecord;

import iaas.repository.BaseRepository;
/**
 * LotteryRecordDao
 * @author lihang 2016-06-27
 *
 */
@Repository
public interface LotteryRecordDao extends BaseRepository<LotteryRecord, Long>,JpaSpecificationExecutor<LotteryRecord>{

	/**查询抽奖总次数*/
	@Query(value="select COUNT(*) from lottery_record where lottery_id = ?1",nativeQuery = true)
	Integer findByLotteryactivityId(Long lotteryactivityid);
	
	
	List<LotteryRecord> findByCorpId(Long corpId);
	
	/** 查询会员的抽奖记录 */
	List<LotteryRecord> findByMemberId(Long memberid);
	
	
	/**查询抽奖总次数*/
	@Query(value="select COUNT(*) from lottery_record where lottery_id =?1 and member_id =?2 and corp_id =?3 and create_time>=?4",nativeQuery = true)
	Integer findByLotteryIdAndMemberIdAndCorpIdAndCreateTimeGreaterThanEqual(Long lotteryactivityid,Long memberid,Long corpid,Date createTime);
}
